#include "io_context.h"
#include "singleton.h"
#include "server.h"

#include <iostream>

#include <boost/asio/io_context.hpp>

int main(void)
{
    try
    {
        //初始化IOContextPool
        auto pool = Singleton<IOContextPool>::GetInstance();

        boost::asio::io_context ioc;
        //捕获对应ioc的信号
        boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
        //异步等待信号
        signals.async_wait([&ioc](boost::system::error_code ec, int signum){
            if(ec)
                return;
            std::cout << "\tSignal: " << signum << "\n";
            ioc.stop();
        });

        Server server(ioc, 8080);
        ioc.run();
    }
    catch (const std::exception& e)
    {
        std::cout << "Exception: " << e.what() << "\n";
        return -1;
    }
    return 0;
}